﻿namespace EasyCMS.Core.Dals.Subject
{
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Collections.Generic;
    using Pismire.Core.Helper.Data;

    public class Test_SqlServer2005 : Sql2005DalBase, ISubject
    {
        #region ISubject 成员

        public void Init(string args)
        {
            this.Args = args;
        }

        #endregion

        public string Args { get; set; }

        #region ISubject 成员


        public EasyCMS.Common.DBComponents.Subject GetByID(int id)
        {
            EasyCMS.Common.DBComponents.Subject s = new EasyCMS.Common.DBComponents.Subject();

            s.Body01 = Args;

            return s;
        }

        #endregion

        #region ISubject 成员


        public List<EasyCMS.Common.DBComponents.Subject> GetList(EasyCMS.Common.Querys.Subject query)
        {
            //初始化定义
            List<EasyCMS.Common.DBComponents.Subject> dataList = new List<EasyCMS.Common.DBComponents.Subject>();
            //recordCount = 0;

            //打开连接连接
            dcm.Open();

            //
            IDataReader reader = null;

            try
            {
                SqlCommand cmd = GetSqlCmd();
                cmd.CommandText = "select * from [Subjects_Test]";
                cmd.CommandType = CommandType.Text;

                //execute
                reader = cmd.ExecuteReader();

                //
                if (reader != null)
                {
                    DataPopulater<EasyCMS.Common.DBComponents.Subject> builder = DataPopulater<EasyCMS.Common.DBComponents.Subject>.CreatePopulater(reader);

                    while (reader.Read())
                    {
                        dataList.Add(builder.Populate(reader));
                    }
                }
            }
            catch (Exception ex)
            {
                //异常记日志
                throw ex;
            }
            finally
            {
                //关闭reader
                if (reader != null)
                {
                    if (!reader.IsClosed) reader.Close();
                    reader.Dispose();
                    reader = null;
                }

                //通知连接管理器关闭数据库连接
                dcm.Close();
            }

            //
            return dataList;
        }

        #endregion

        #region ISubject 成员


        public EasyCMS.Common.DBComponents.Subject GetByCodeName(string codeName)
        {
            throw new NotImplementedException();
        }

        public List<EasyCMS.Common.DBComponents.Subject> GetList(EasyCMS.Common.Querys.Subject query, out int recordCount)
        {
            throw new NotImplementedException();
        }

        public Pismire.Core.Components.ExcuteState Add(ref EasyCMS.Common.DBComponents.Subject subject)
        {
            throw new NotImplementedException();
        }

        public Pismire.Core.Components.ExcuteState Update(ref EasyCMS.Common.DBComponents.Subject subject)
        {
            throw new NotImplementedException();
        }

        public Pismire.Core.Components.ExcuteState Delete(int id)
        {
            throw new NotImplementedException();
        }

        public Pismire.Core.Components.ExcuteState CreateSubjectTable(string subjectMark)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
